package com.uraurora.crescent.function.functools.memoizer;

import com.google.common.cache.Cache;
import com.uraurora.crescent.function.Func3;
import com.uraurora.crescent.tuple.ITuple;
import com.uraurora.crescent.tuple.Tuple;

import java.util.concurrent.Future;

public class MemoizerFunc3<T1, T2, T3, RT>
        extends AbstractMemoizer<RT>
        implements Func3<T1, T2, T3, RT> {

    private final Func3<? super T1, ? super T2, ? super T3, ? extends RT> computable;

    public MemoizerFunc3(Func3<? super T1, ? super T2, ? super T3, ? extends RT> computable,
                         Cache<ITuple, Future<RT>> Cache) {
        super(Cache);
        this.computable = computable;
    }

    public MemoizerFunc3(Func3<? super T1, ? super T2, ? super T3, ? extends RT> computable){
        super();
        this.computable = computable;
    }

    @Override
    public RT on(T1 t1, T2 t2, T3 t3) {
        return compute(Tuple.of(t1, t2, t3), ()->computable.on(t1, t2, t3));
    }

    @Override
    @Deprecated
    public MemoizerFunc3<T1, T2, T3, RT> memoize(){
        throw new UnsupportedOperationException();
    }

    @Override
    @Deprecated
    public MemoizerFunc3<T1, T2, T3, RT> memoize(Cache<ITuple, Future<RT>> Cache){
        throw new UnsupportedOperationException();
    }
}
